 package com.hinata.hinataimageloader;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

 public class MainActivity extends Activity implements RecyclerViewItemClickListener,OnClickListener {
     String imageUri;

     ImageView imageViewBig;
     ImageButton ibtnHomeworkGetImage;
     Button btnHomeworkSubmit;


     private RecyclerView mRecyclerView;
     private GalleryAdapter mAdapter;
     private List<Integer> mDatas;

     @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

         initDatas();


         ibtnHomeworkGetImage = (ImageButton) this.findViewById(R.id.imgbtn_homework_get_image);
         btnHomeworkSubmit=(Button) this.findViewById(R.id.btn_homework_submit);
         imageViewBig=(ImageView) this.findViewById(R.id.img_main_big);
         //得到控件
         mRecyclerView = (RecyclerView) findViewById(R.id.id_recyclerview_horizontal);
         //设置布局管理器
         LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
         linearLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
         mRecyclerView.setLayoutManager(linearLayoutManager);
         //设置适配器
         mAdapter = new GalleryAdapter(this, mDatas);
         mRecyclerView.setAdapter(mAdapter);
         mAdapter.setOnItemClickListener(this);

         ibtnHomeworkGetImage.setOnClickListener(this);





     }

     private void initView(){

     }

     private void initDatas() {
         mDatas = new ArrayList<>(Arrays.asList(R.drawable.tuzi,
                 R.drawable.papers, R.drawable.tuzi2, R.drawable.papers, R.drawable.tuzi,
                 R.drawable.tuzi, R.drawable.tuzi, R.drawable.tuzi, R.drawable.tuzi));
     }

     /**
      * Item click
      */
     @Override
     public void onItemClick(View view, int postion) {

         Toast.makeText(this, "chutian"+postion, Toast.LENGTH_SHORT).show();

         ImageView imgCurrent=(ImageView) view.findViewById(R.id.id_index_gallery_item_image);
         imgCurrent.setDrawingCacheEnabled(true);
         Bitmap temp = Bitmap.createBitmap(imgCurrent.getDrawingCache());
         imageViewBig.setImageBitmap(temp);
         imgCurrent.setDrawingCacheEnabled(false);
     }

     public void onClick(View v) {
         switch (v.getId()) {
             case R.id.imgbtn_homework_get_image:
                 startActivity(new Intent(MainActivity.this,ImageChoiceActivity.class));
                 break;
             case R.id.btn_homework_submit:

                 break;
             default:
                 break;
         }
     }

 }
